﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZG_member.BLL;

namespace ZG_member
{
    public partial class CardTemplatePrint : Form
    {
        public CardTemplatePrint()
        {
            InitializeComponent();
            this.Opacity = 0;
        }

        public static string temp ;
     
        public static ZG_member.Model.memberInfo mode;

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //temp = temp.Replace("\n", "#");
            //string[] users = temp.Split('#');
            //string muban = "会员卡号#卡片类型#会员姓名#性　　别#卡片状态#办卡日期#截止日期#累计积分#本次积分#本次消费#储值余额#折扣金额#实际消费";
            //string[] mubanArray = muban.Split('#');
            //string[] ModelArray = new string[] {mode.memberCardId,mode.CardType,mode.memberName,mode.Gender,mode.Status,mode.createDate.ToString(),mode.expiresDate.ToString(),mode.point.ToString(),"0","0",mode.Balance.ToString(),"",mode.consume.ToString()};
            // temp = "";

            //for (int i = 0; i < users.Length-1; i++)
            //{
            //    for (int j = 0; j < mubanArray.Length; j++)
            //    {
            //        if (users[i] == mubanArray[j])
            //        {
            //            temp += users[i]+":" + ModelArray[j] + "\n";
            //        } 
            //    }
            //}
            
           byte[] printer = System.Text.Encoding.Default.GetBytes("NPPrinter1.1");
           int x = int.Parse(this.cmbX.Text);
           int y = int.Parse(this.cmbY.Text);
           byte[] fontname = System.Text.Encoding.Default.GetBytes(this.cmbFont.Text);
           int fontsize = int.Parse(this.cmbSize.Text);
           int direction = 0;
           if (this.RidT1.Checked)
           {
               direction = Convert.ToInt32(RidT1.Tag.ToString());
           }
           if (this.RidT2.Checked)
           {
               direction = Convert.ToInt32(RidT2.Tag.ToString());
           }

           CardTemplateDesignMainForm tm = new CardTemplateDesignMainForm();

           byte[] strText = System.Text.Encoding.Default.GetBytes(temp);

           //传入打印方法
            int ret = RPCClass.RCP11Class.PrintStr(printer, strText, x, y, direction, fontname, fontsize);
           if (ret == 0)
           {
               MessageBox.Show("打印成功");
           }
           else
           {
               MessageBox.Show("打印失败");
           }
        }

        private void CardTemplatePrint_Load(object sender, EventArgs e)
        {
            this.timer1.Start();
            this.cmbX.SelectedIndex = 0;
            this.cmbY.SelectedIndex = 0;
            this.cmbFont.SelectedIndex = 0;
            this.cmbSize.SelectedIndex = 0;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Left += 2;
            this.Opacity += 0.1;
            if (Opacity == 1)
            {
                this.timer1.Stop();

            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            this.Top = this.Top + 10;
            this.Opacity = this.Opacity - 0.06;
            if (Opacity <= 0)
            {
                this.timer2.Stop();
                this.Close();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.timer2.Start();
        }
        int flag = 0;
        private void CardTemplatePrint_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (flag == 0)
            {
                e.Cancel = true;
                flag = 1;
                this.timer2.Start();
            }
        }
    }
}
